<?php
header("Content-Type:text/html;charset=utf-8");
/**
 * catlist.php 显示cat数据库栏目
 * 
 * @author 老洪
 * @link www.baidu.com
 * @since 2020年11月9日15:56:00
 * @copyright CGX
 */

//判断用户是否登录
// $_SESSION['s_username'] = null;
session_start();
$sessions = empty($_SESSION['s_username']) ? '' : $_SESSION['s_username'];
if ($sessions == '') {
  //用户名或密码不存在，弹出‘该用户不存在’
  echo "<script>alert('请先登录账户！');window.location.href='login.php'</script>";
  exit();
}

//分别引入前端模板
require './lib/init.php';
// require './conn.php';
// //查询结果 放置内容到mysqli_fetch_assoc里面，一个$data数据放置
// $sql = "select * from cat";
// $res = mysqli_query($conn, $sql);
// if (!$res) {
//   echo mysqli_error($conn);
//   //写日志
//   exit();
// }
// $data = array();
// while ($row = mysqli_fetch_assoc($res)) {
//   $data[] = $row;
// }
// var_dump($data);

// $sql = "select * from cat";
// $data = mGetAll($sql);

$sql = "select count(*) as num from cat";
$num = mGetOne($sql); //获取总页数
$cnt = 3; //每页显示三篇文章
$curr = isset($_GET['page']) ? $_GET['page'] : 1; //当前页码数，从地址栏的page值获取
$pages = cPager($num, $cnt, $curr);


$sql = 'select * from cat order by cat_id asc limit ' . ($curr - 1) * $cnt . ',' . $cnt;
//$sql = "select * from art";
$data = mGetAll($sql);

require './view/admin/catlist.html';
